<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>- 注册</title>
<meta name="keywords" content="(www.eblog.site),博文分享，技术博文，影音推荐，美食分享，生活技巧，笑话大全"/>
<meta name="description" content="eBlog分享网(www.eblog.site)为广大朋友们提供有技术的博文，最新最热门的电影音乐。看到就流口水的美食，各种生活技巧，笑喘不过气的笑话！ "/>
<link rel="shortcut icon" href="assets/manager/favicon.ico">
<link href="assets/manager/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
<link href="assets/manager/css/font-awesome.css?v=4.4.0" rel="stylesheet">
<link href="assets/manager/css/plugins/iCheck/custom.css" rel="stylesheet">
<link href="assets/manager/css/animate.css" rel="stylesheet">
<link href="assets/manager/css/style.css?v=4.1.0" rel="stylesheet">
<script>if(window.top !== window.self){ window.top.location = window.location;}</script>
</head>
<body class="gray-bg">
	<div class="middle-box text-center loginscreen   animated fadeInDown">
		<div>
			<div>
				<h1 class="logo-name">E</h1>
			</div>
			<h3>欢迎注册 eBlog</h3>
			<p>创建一个eBlog新账户</p>
				<div class="form-group">
					<input type="text" id="name" class="form-control" placeholder="用户名，字母开头5-16位数字字母组合"
						required="">
				</div>
				<div class="form-group">
					<input type="password" id="password" class="form-control" placeholder="密码,字母开头6-18位数字字母组合"
						required="">
				</div>
				<div class="form-group">
					<input type="password" id="cpassword" class="form-control" placeholder="确认密码,字母开头6-18位数字字母组合"
						required="">
				</div>
				<div class="form-group">
					<input type="text" id="Mphone" class="form-control" placeholder="请输入手机号码"
						required="">
				</div>
				<div class="form-group">
					<input type="text" id="Email" class="form-control" placeholder="Email"
						required="">
				</div>
				<div class="form-group">
					性别： 
					<label class="radio-inline"> 
						<input type="radio" checked value="男" id="sexM" name="sex">男</label> 
					<label class="radio-inline">
						<input type="radio" value="女" id="sexW" name="sex">女</label>
				</div>
				<button type="submit" id="register" class="btn btn-primary block full-width m-b">注册</button>
				<p class="text-muted text-center">
					<small>已经有账户了？</small><a href="login">点此登录</a> | 
					<a href="/"><small>返回首页</small></a>
				</p>
		</div>
	</div>
	<!-- 全局js -->
	<script src="assets/manager/js/jquery.min.js?v=2.1.4"></script>
	<script src="assets/manager/js/bootstrap.min.js?v=3.3.6"></script>
	<!-- iCheck -->
	<script src="assets/manager/js/plugins/iCheck/icheck.min.js"></script>
	<script>
        $(document).ready(function () {
        	//注册
        	var $checkByName = false;
        	$("#name").blur(function(){
        		$name = $(this).val();
        		$.post("checkByName",{"name":$name},function(data){
        			if(data == 1){
        				alert("用户名已存在！");
        				$checkByName = true;
        			}else{
        				$checkByName = false;
        			}
        		});
        	});
        	$("#register").click(function(){
        		if($checkByName){
        			alert("用户名已存在！");
        		}
        		else if($("#name").val() == "" || $("#password").val() == ""){
        			alert("用户名和密码是必须的！");
        		}
        		else if($("#password").val() != $("#cpassword").val()){
        			alert("两次密码不一样！");
        		}else{
        			register();
        		}
        	});
        	function register(){
        		$sex = $(".form-group input[type='radio']:checked").val();
        		$dataObject={
        				name:$("#name").val(),
        				password:$("#password").val(),
        				phone:$("#Mphone").val(),
        				email:$("#Email").val(),
        				sex:$sex
        		}
        		
        		$.ajax({
    				type:"post",
    				url:"register.do",
    				dataType:"json",
    				contentType:"application/json;charset=utf-8",
    				data:JSON.stringify($dataObject),
    				success:function(data){
    					if(data.res == 1 && data.newUserRole == 1){
    						alert("注册成功！");
    						window.location.href="login"
    					}else{
    						alert(data.resMsg);
    					}
    				}
    			})
        	};
        	//注册
            $('.i-checks').iCheck({
                checkboxClass: 'icheckbox_square-green',
                radioClass: 'iradio_square-green',
            });
        });
    </script>
</body>
</html>
